package com.vcc.data.mapper;

import com.mybatisflex.core.BaseMapper;
import com.vcc.data.entity.Role;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.Optional;

@Mapper
public interface RoleMapper extends BaseMapper<Role> {

    @Select("select r.* from vcc_user_role ur left join vcc_role r on ur.role_id = r.id where ur.user_id = #{userId}")
    Optional<Role> findByUserId(@Param("userId") Long userId);

    @Update("update vcc_user_role set role_id = #{roleId} where user_id = #{userId} and role_id = #{sourceRoleId}")
    int updateRoleByUserId(@Param("userId") Long userId, @Param("roleId") Long roleId, @Param("sourceRoleId") Long sourceRoleId);
}
